//
//  contactsInforCell.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/13.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "contactsInforCell.h"

@implementation contactsInforCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.selectionStyle =  UITableViewCellSelectionStyleNone;
    [self setup];
    
}

- (void)setup {
    
    self.contactInforLabel.textColor = kSubitleColor;
    self.contactInforLabel.text = MYLocalizedString(@"TICKET_USER_INFO", nil);
    
    self.emailTextField.placeholder = MYLocalizedString(@"TICKET_USER_EMAIL_PLACEHOLDER", nil);
    self.emailTextField.delegate = self;
    self.emailTextField.textColor = kContentColor;
    
    
    self.nameTextField.placeholder = MYLocalizedString(@"TICKET_CONTACT_NAME", nil);
    self.nameTextField.delegate = self;
    self.nameTextField.textColor = kContentColor;
    
    
    self.phoneNumTextField.placeholder = MYLocalizedString(@"TICKET_USER_PHONE_PLACEHOLDER", nil);
    self.phoneNumTextField.delegate = self;
    self.phoneNumTextField.textColor = kContentColor;
    
    self.countryCodeTextField.textColor = kContentColor;
    self.countryCodeTextField.userInteractionEnabled = NO;
    self.countryCodeTextField.placeholder = MYLocalizedString(@"LOGIN_PLACE", nil);
}


- (void)configDataWith:(TicketMemberInfoModel *)model{
    
    self.emailTextField.enabled = NO;
    self.emailTextField.text = model.email;
    
    self.nameTextField.enabled = NO;
    self.nameTextField.text = model.realname;
    
    
    self.phoneView.userInteractionEnabled = NO;
    self.countryCodeTextField.text = model.countrycode;
    self.phoneNumTextField.text = model.phoneNumber;
    
}

- (void)setMemberModel:(TicketMemberInfoModel *)memberModel {
    
    _memberModel = memberModel;
    
}

- (void)goSelectDate {
    [self closeKeyBoard];
    [self.superVC selectBirthdayDate];
}
- (IBAction)goSelectRegionCode:(UIButton *)sender {
    
    [self closeKeyBoard];
    SelectCountryVC * vc = [[SelectCountryVC alloc] init];
    vc.delegate = self;
    self.isNeedCode = YES;
    [vc showWithVC:self.superVC];
}

- (void)goSelectedRegion {
    
    SelectCountryVC * vc = [[SelectCountryVC alloc] init];
    vc.delegate = self;
    vc.isOnlyCity = YES;
    
    [vc showWithVC:self.superVC];
}


#pragma mark   -- SelectCountryVCDelegate

- (void)selectedCountry:(Country *)country {
    
    self.countryCodeTextField.text = country.code;
    self.memberModel.countrycode = country.code;
}

#pragma  mark  --
- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    if (textField == self.emailTextField) {
        
        self.memberModel.email = self.emailTextField.text;// 原 名字不要换成邮箱了
    }else if(textField == self.nameTextField){
        self.memberModel.realname = self.nameTextField.text;
    }else if(textField == self.phoneNumTextField){
        self.memberModel.phoneNumber = self.phoneNumTextField.text;
    }
}


-(void)closeKeyBoard{
    [self.nameTextField endEditing:YES];
    [self.phoneNumTextField endEditing:YES];
    [self.emailTextField endEditing:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [super touchesBegan:touches withEvent:event];
    
    [self closeKeyBoard];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

